package fhp.hlhj.giantfold
import android.app.Application
import cn.jpush.android.api.JPushInterface
import com.alibaba.baichuan.android.trade.AlibcTradeSDK
import com.alibaba.baichuan.android.trade.callback.AlibcTradeInitCallback
import com.alibaba.baichuan.trade.biz.core.taoke.AlibcTaokeParams
import com.kepler.jd.Listener.AsyncInitListener
import com.kepler.jd.login.KeplerApiManager
import com.lzy.okgo.OkGo
import com.lzy.okgo.cookie.CookieJarImpl
import com.lzy.okgo.cookie.store.MemoryCookieStore
import com.lzy.okgo.interceptor.HttpLoggingInterceptor
import com.mob.MobApplication
import com.zipingfang.android.yst.YoukeApi
import fhp.hlhj.giantfold.utils.LoadingUtils
import fhp.hlhj.giantfold.utils.LogUtil
import fhp.hlhj.giantfold.utils.MyUtils
import okhttp3.OkHttpClient
import org.litepal.LitePal
import java.util.HashMap
import java.util.logging.Level
/**
 * author: ShuaiTao
 * data: on 2017\11\17 0017 10:34
 * E-Mail: bill_dream@sina.com
 */
class MyApp :MobApplication() {
    override fun onCreate() {
        super.onCreate()
        /*有客云*/
        YoukeApi.initialize(this)
        YoukeApi.getInstance().setDebugModel(true);
        YoukeApi.getInstance().setRunInBackGround(true);
        /*开普勒*/
        KeplerApiManager.asyncInitSdk(this,"29cbb099a1924034a6aee10997296e74","1d4d051201864e5c86e6519e01b0c4f3"
        ,object :AsyncInitListener{
            override fun onSuccess() {
                LogUtil.log("开普勒初始化成功")
            }
            override fun onFailure() {
                LogUtil.log("开普勒初始化失败")
            }
        })
        /*Jpush*/
        JPushInterface.init(this)
        /*Litepal*/
        LitePal.initialize(this)
        /*utils*/
        MyUtils.initUtil(applicationContext)
        /*OKGO*/
        OkGo.getInstance().init(this)
        val builder=OkHttpClient.Builder()
        builder.cookieJar(CookieJarImpl(MemoryCookieStore()))
        val loggingInterceptor = HttpLoggingInterceptor("OkGo")
        loggingInterceptor.setPrintLevel(HttpLoggingInterceptor.Level.BODY)
        loggingInterceptor.setColorLevel(Level.INFO)
        builder.addInterceptor(loggingInterceptor)
        OkGo.getInstance().okHttpClient = builder.build()
        /*阿里百川*/
        AlibcTradeSDK.asyncInit(this,object :AlibcTradeInitCallback{
            override fun onSuccess() {
                LogUtil.log("使能商城sdk成功")
                val params = AlibcTaokeParams()
                params.pid="mm_116147303_36832537_132678582"
                params.adzoneid="132678582"
                params.subPid="mm_116147303_36832537_132678582"
                params.extraParams = HashMap<String, String>()
                params.extraParams.put("taokeAppkey","24624369")
                AlibcTradeSDK.setTaokeParams(params)
            }
            override fun onFailure(p0: Int, p1: String?) {
                LogUtil.log("使能商城sdk失败"+p1.toString()+p0.toString())
            }
        })

    }
}